package com.tzz.service.impl;

import com.alibaba.fastjson2.JSONObject;
import com.tzz.config.MockFdcGpsArriveConfig;
import com.tzz.entity.GoodsArriveMsg;
import com.tzz.service.GoodMonitorService;
import com.tzz.utils.ModelDataUtil;
import com.tzz.utils.ProducerMQUtil;
import com.tzz.utils.RandomUtil;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;

@Service
public class GoodMonitorServiceImpl implements GoodMonitorService {

    @Autowired
    MockFdcGpsArriveConfig mockFdcGpsArriveConfig;

    @Override
    public void productMonitorMsg(GoodsArriveMsg goodsArriveMsg) {
        JSONObject fdcReceiveAsnOrderInfo = ModelDataUtil.getRequestDataModel("fdcReceiveAsnOrderInfo");
        convertGoodArriveMsg(fdcReceiveAsnOrderInfo,goodsArriveMsg);
        System.out.println("================================================================");
        System.out.println(fdcReceiveAsnOrderInfo);
        DefaultMQProducer producer = ProducerMQUtil.getProducer(mockFdcGpsArriveConfig.getGroup());
        ProducerMQUtil.sendMsg(producer,mockFdcGpsArriveConfig.getNameServer(), mockFdcGpsArriveConfig.getTopic(), fdcReceiveAsnOrderInfo);
    }

    private void convertGoodArriveMsg(JSONObject sourceDataModel,GoodsArriveMsg goodsArriveMsg){
        sourceDataModel.put("stationId",goodsArriveMsg.getStationId());
        sourceDataModel.put("orderType",goodsArriveMsg.getStationId());
        sourceDataModel.put("orderId", RandomUtil.getRandomId("monitor"));
        sourceDataModel.put("cargoWarehouseId",goodsArriveMsg.getCargoWarehouseId());
        sourceDataModel.put("deliveryMode",goodsArriveMsg.getDeliveryMode());
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        sourceDataModel.put("leaveStoreTime",simpleDateFormat.format(goodsArriveMsg.getLeaveStoreTime()));
        sourceDataModel.put("logisticsArriveTime",simpleDateFormat.format(goodsArriveMsg.getLogisticsArriveTime()));
//        return sourceDataModel;
    }

}
